var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function (req, res, next) {
  res.render('index', {
    title: 'Express'
  });
});

router.ws('/conectWs', function (ws) {
  console.log("连接成功！");
  ws.send(JSON.stringify(ws))
  ws.on('open', function open() {
    console.log('connected');
    ws.send(Date.now());
  });
  ws.on('close', function close() {
    console.log('disconnected');
  });
  ws.on('message', function incoming(data) {
    console.log("客服端发来消息" + data);
    ws.send(data);
  });
});

router.post('/sendMsg', function (req, res, next) {
  const ress=req.body;
  res.send(ress)
});

module.exports = router;